using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using SubSonic;

namespace Commerce.Common
{

    public static class Lookups
    {
        /// <summary>
        /// This is a simple function to use with lookup tables
        /// that are not represented with a business object.
        /// </summary>
        /// <param name="tableName">Name of the table to query. All results will be returned</param>
        /// <returns>IDataReader</returns>
        public static IDataReader GetList(string tableName)
        {

            return new Query(tableName).ExecuteReader();

        }

        /// <summary>
        /// This is a simple function to use with lookup tables
        /// that are not represented with a business object.
        /// You can supply a parameter name and value
        /// </summary>
        /// <param name="tableName">The name of the table</param>
        /// <param name="paramField">The column to use </param>
        /// <param name="paramValue">The column value</param>
        /// <returns></returns>
        public static IDataReader GetListByIntParam(string tableName, string paramField, int paramValue)
        {
            return new Query(tableName).AddWhere(paramField,paramValue).ExecuteReader();

        }
        /// <summary>
        /// This is a simple function to use with lookup tables
        /// that are not represented with a business object.
        /// You can supply a parameter name and value
        /// </summary>
        /// <param name="tableName">The name of the table</param>
        /// <param name="paramField">The column to use </param>
        /// <param name="paramValue">The column value</param>
        /// <returns></returns>
        public static IDataReader GetListByStringParam(string tableName, string paramField, string paramValue)
        {
            return new Query(tableName).AddWhere(paramField, paramValue).ExecuteReader();

        }

        public static void QuickAdd(string tableName, string paramField, string paramValue)
        {

            QueryCommand cmd = new QueryCommand("INSERT INTO " + tableName + " (" + paramField + ") VALUES(@p1) ");
            cmd.AddParameter("@p1", paramValue);
            DataService.ExecuteQuery(cmd);

        }
    
    }
}
